
function popupTowerContract() {
	  var win = new Ext.Window({
	        modal : true,
	        height : 0.4 * screen.height,
	        width : 1080,
	        border : false,
	        resizable : false,
	        closable : true,
	        title : 'SITE TOWER CONTRACT',
        layout : 'fit',
        titleAlign : 'center',
        frame : true,
        autoScroll : true,
        listeners: {
          	afterrender: function () {
              	Ext.getCmp('assetIdTowContract').setValue(Ext.getCmp('assetIdTower').getValue());   
              	var assetId = Ext.getCmp("assetIdTowContract").getValue();
				Ext.getStore('AssetDataMaster.AssetTowerContract').removeAll();
				Ext.getStore('AssetDataMaster.AssetTowerContract').getProxy().url = './Services/Asset/AssetTowerContract/List?assetId=' + assetId;
				Ext.getStore('AssetDataMaster.AssetTowerContract').load();
				Ext.getStore('AssetDataMaster.AssetTowerContract').on({
					load:function(){
						var store = Ext.getStore('AssetDataMaster.AssetTowerContract').getAt(0);
						if(store != null){
							Ext.getCmp('docskrpd').setValue(store.get('CONTRACT_NO'));
						}
						
					}
				});
			}
				
      	},
        items : [
             {
                xtype: 'form',
                id: 'formAssetTowContract',
                width: 1080,
                heigth: 100,
                layout: 'hbox',
                border: false,
                method: 'POST',
                url: './Services/Asset/AssetTowerContract/Add',
                margin: '0 10 0 0',
                items: [
                    {
                        xtype: 'panel',
                        width: 320,
                        heigth:  0.7 * screen.height,
                        layout: 'vbox',
                        border: false,
                        margin: '10 10 10 10',
                        items: [
                            {
	                            xtype: 'hiddenfield',
	                            cls: 'black',
	                            id : 'contractIdTowContract',
	                            name: 'SITE_TOWER_CONTRACT_HISTORY_ID',
	                            margin: '5 10 5 25',
	                            labelWidth: 130 / 1366 * screen.width,
	                            width: 330 / 1366 * screen.width,
	                            fieldLabel: 'Contract ID',
	                            msgTarget: 'title',
	                            allowBlank: true,
	                            validateBlank: false
	
	                        },
	                        {
	                            xtype: 'hiddenfield',
	                            cls: 'black',
	                            id : 'assetIdTowContract',
	                            name: 'ASSET_DETAIL_ID',
	                            margin: '5 10 5 25',
	                            labelWidth: 130 / 1366 * screen.width,
	                            width: 330 / 1366 * screen.width,
	                            fieldLabel: 'Asset ID',
	                            msgTarget: 'title',
	                            allowBlank: true,
	                            validateBlank: false
	
	                        },
                            {
		                        xtype: 'textfield',
		                        cls: 'black',
		                        name: 'CONTRACT_NO',
		                        margin: '0 10 10 5',
		                        labelWidth: 100 / 1366 * screen.width,
		                        width: 315 / 1366 * screen.width,
		                        fieldLabel: 'SKRD / RPM No',
		                        msgTarget: 'title',
		                        allowBlank: true,
		                        validateBlank: false
		
		                    },
                            {
                            	xtype: 'panel',
	                            border: false,
	                            layout: 'hbox',
	                            items: [
                                    {
				                        xtype: 'datefield',
				                        cls: 'black',
				                        name: 'CONTRACT_START_DATE',
				                        margin: '0 10 10 5',
										format : 'Y/m/d',
				                        labelWidth: 100 / 1366 * screen.width,
				                        width: 200 / 1366 * screen.width,
				                        fieldLabel: 'Valid Period',
				                        msgTarget: 'title',
				                        allowBlank: true,
				                        validateBlank: false
			                        },
				                    {
				                        xtype: 'datefield',
				                        cls: 'black',
				                        name: 'CONTRACT_END_DATE',
				                        margin: '0 10 10 5',
										format : 'Y/m/d',
				                        width: 100 / 1366 * screen.width,
				                        msgTarget: 'title',
				                        allowBlank: true,
				                        validateBlank: false
			                        }    
	                            ]		
		                    },
                            {
		                        xtype: 'numberfield',
		                        cls: 'black',
		                        name: 'EXPENSE_AMOUNT',
		                        margin: '0 10 10 5',
		                        labelWidth: 100 / 1366 * screen.width,
		                        width: 315 / 1366 * screen.width,
		                        fieldLabel: 'Expense Amount',
		                        msgTarget: 'title',
		                        allowBlank: true,
		                        validateNumber: true
		
		                    },
		                    {
			   		             xtype: 'fileuploadfield',
			   		             id: 'docTowContract',
			   		             emptyText: 'Select a document to upload...',
			   		             name:'FILE',
			   		             fieldLabel: 'Document',
			   		             buttonText: '...',
			   		             labelWidth: 100/1366*screen.width,
			   		             width: 315/1366*screen.width,
			   		             margin:'0 10 10 5'
		                    },
		                    {
                                xtype: 'combobox',
                                cls: 'black',
                                name: 'ENABLED',
                                margin: '0 10 10 5',
                                labelWidth: 100 / 1366 * screen.width,
                                width: 315/1366 * screen.width,
                                fieldLabel: 'Active',
                                emptyText: 'Active',
                                store: [['True', 'Yes'], ['False', 'No']],
                                msgTarget: 'title',
                                allowBlank: true,
                                validateBlank: false
                            },
                            {
                                xtype: 'panel',
                                width: 345,
                                heigth: 100,
                                layout: 'hbox',
                                border: false,
                                margin: '0 10 0 0',
                                items: [
                                    {
                                        xtype: 'button',
                                        width: 60,
                                        height: 30,
                                        margin: '0 10 0 110',
                                        text: 'Add',
                                        id: 'btnSubmitTowContract',
                                        handler: function () {
                                            Ext.getCmp('formAssetTowContract').getForm().submit({
                                            	 waitMsg : 'Please Wait ....',
												success: function(form, action) {
													Ext.Msg.alert('Submited', action.response.responseText);
												},
												failure: function(form, action) {
													Ext.Msg.alert('Submited', action.response.responseText);
		                                            Ext.getCmp('formAssetTowContract').getForm().reset;
		                                            Ext.getStore('AssetDataMaster.AssetTowerContract').load();
												}
											});
                                        }
                                    },
                                    {
                                        xtype: 'button',
                                        width: 60,
                                        height: 30,
                                        margin: '0 10 0 45',
                                        text: 'Cancel',
                                        id: 'btnCancelTowContract',
                                        handler: function () {
                                            Ext.getCmp('formAssetTowContract').getForm().reset;
                                            Ext.getStore('AssetDataMaster.AssetTowerContract').load();
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
		            	 xtype : 'gridpanel',
		            	 id : 'gridAssetTowContract',
		            	 height : 0.33 * screen.height,
		            	 autoScroll : 'true',
		            	 width : 700,
		            	 region : 'center',
		            	 columnLines : true,
		            	 forceFit : true,
                         margin: '10 10 10 10',
		            	 store : 'AssetDataMaster.AssetTowerContract',
		            	 listeners : {
		        	 		afterrender : function() {
								
		             	 	}
		      			 },
				          columns: [
				              {dataIndex: 'CONTRACT_NO', text: 'CONTRACT NO', align: 'left'},
				              {dataIndex: 'CONTRACT_START_DATE', text: 'START DATE', align: 'left'},
				              {dataIndex: 'CONTRACT_END_DATE', text: 'END DATE', align: 'left'},
				              {dataIndex: 'EXPENSE_AMOUNT', text: 'AMOUNT', align: 'left'},
				              {
		                      	    xtype: 'actioncolumn',
		                      	    text : 'DOCUMENT',
		                      	    align : 'center',
		                      	    renderer: function (value, metadata, record) {
		                      	    	var document = record.get('ATTACH_FILE');
		                      	    	if (document=="null"){
		                      	    		this.items[0].icon = '';
		                      	    	}else{
		                      	    		var typefile=document.split(".");
		                      	    		 if (typefile[1]=="pdf"){ 
		                      	    			 this.items[0].icon = 'images/pdf-icon.png'; 
		                      	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
		                      	    			 this.items[0].icon = 'images/Word-icon.png';  
		                      	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
		                      	    			 this.items[0].icon = 'images/Excel-icon.png';  
		                      	    		 }else if (typefile[1]=="jpeg" || typefile[1]=="xls"){ 
		                      	    			 this.items[0].icon = 'images/images-icon.jpg';  
		                      	    		 }
		                      	    	}
		                      	    },
		                      	    items: [{
		                      	        tooltip: 'Show Document',
		                      	        handler: function (grid, rowIndex, colIndex) {
		                      	        	 var rec = grid.getStore().getAt(rowIndex);
		                      	        	 var typefile=rec.get('ATTACH_FILE').split(".");
		                      	        	 console.log (rec.get('ATTACH_FILE'));
		                      	        	 if (typefile[1]=="pdf"){
		                      	        		window.open('./Services/Asset/doc/pdf/'+rec.get('ATTACH_FILE')); 
		                      	        	 }else{
		                      	        		 window.open('./Services/Asset/doc/img/'+rec.get('ATTACH_FILE'));  
		                      	        	 }
		                      	        }
		                      	    }]
				              },
				              {dataIndex: 'ENABLED', text: 'ENABLED', align: 'left'}
				          ],
			      			listeners : {
				                itemdblclick : function(grid, record) {
				                	var cntId = record.get('SITE_TOWER_CONTRACT_HISTORY_ID');
				                	console.log (cntId);
			                		Ext.Ajax.request({
			                		    method: "GET",
			                		    dataType: "json",
			                		    url: "./Services/Asset/AssetTowerContract/"+cntId,
			                		    async: false	,
			                		    success: function(c) {
			                		    	var jsonResults= $.parseJSON(c.responseText);
			                		    	data = jsonResults.item[0];
			                		    	console.log (data);
			                		    	Ext.getCmp('formAssetTowContract').getForm().setValues(data);
			                		    	Ext.getCmp('btnSubmitTowContract').setText('Update');	
		                		        }
		                		    });	
				                }
                		    }
		            }   
                ] 
            }
                
         ]
      }).show();

}


function popupTowerImb() {
	  var win = new Ext.Window({
	        modal : true,
	        height : 0.4 * screen.height,
	        width : 1080,
	        border : false,
	        resizable : false,
	        closable : true,
	        title : 'SITE TOWER IMB',
        layout : 'fit',
        titleAlign : 'center',
        frame : true,
        autoScroll : true,
        listeners: {
          	afterrender: function () {
              	Ext.getCmp('assetIdTowImb').setValue(Ext.getCmp('assetIdTower').getValue());   
              	var assetId = Ext.getCmp("assetIdTowImb").getValue();
				Ext.getStore('AssetDataMaster.AssetTowerImb').removeAll();
				Ext.getStore('AssetDataMaster.AssetTowerImb').getProxy().url = './Services/Asset/AssetTowerImb/List?assetId=' + assetId;
				Ext.getStore('AssetDataMaster.AssetTowerImb').load();
				Ext.getStore('AssetDataMaster.AssetTowerImb').on({
					load:function(){
						var store = Ext.getStore('AssetDataMaster.AssetTowerImb').getAt(0);
						if(store != null){
							Ext.getCmp('docimb').setValue(store.get('IMB_NO'));
						}
						
					}
				});
			}
				
      	},
        items : [
             {
                xtype: 'form',
                id: 'formAssetTowImb',
                width: 1080,
                heigth: 100,
                layout: 'hbox',
                border: false,
                method: 'POST',
                url: './Services/Asset/AssetTowerImb/Add',
                margin: '0 10 0 0',
                items: [
                    {
                        xtype: 'panel',
                        width: 320,
                        heigth:  0.7 * screen.height,
                        layout: 'vbox',
                        border: false,
                        margin: '10 10 10 10',
                        items: [
                            {
	                            xtype: 'hiddenfield',
	                            cls: 'black',
	                            id : 'imbIdTowImb',
	                            name: 'SITE_TOWER_IMB_HISTORY_ID',
	                            margin: '5 10 5 25',
	                            labelWidth: 130 / 1366 * screen.width,
	                            width: 330 / 1366 * screen.width,
	                            fieldLabel: 'IMB ID',
	                            msgTarget: 'title',
	                            allowBlank: true,
	                            validateBlank: false
	
	                        },
	                        {
	                            xtype: 'hiddenfield',
	                            cls: 'black',
	                            id : 'assetIdTowImb',
	                            name: 'ASSET_DETAIL_ID',
	                            margin: '5 10 5 25',
	                            labelWidth: 130 / 1366 * screen.width,
	                            width: 330 / 1366 * screen.width,
	                            fieldLabel: 'Asset ID',
	                            msgTarget: 'title',
	                            allowBlank: true,
	                            validateBlank: false
	
	                        },
                            {
		                        xtype: 'textfield',
		                        cls: 'black',
		                        name: 'IMB_NO',
		                        margin: '0 10 10 5',
		                        labelWidth: 100 / 1366 * screen.width,
		                        width: 315 / 1366 * screen.width,
		                        fieldLabel: 'IMB No',
		                        msgTarget: 'title',
		                        allowBlank: true,
		                        validateBlank: false
		
		                    },
                            {
                            	xtype: 'panel',
	                            border: false,
	                            layout: 'hbox',
	                            items: [
                                    {
				                        xtype: 'datefield',
				                        cls: 'black',
				                        name: 'IMB_START_DATE',
				                        margin: '0 10 10 5',
										format : 'Y/m/d',
				                        labelWidth: 100 / 1366 * screen.width,
				                        width: 200 / 1366 * screen.width,
				                        fieldLabel: 'Valid Period',
				                        msgTarget: 'title',
				                        allowBlank: true,
				                        validateBlank: false
			                        },
				                    {
				                        xtype: 'datefield',
				                        cls: 'black',
				                        name: 'IMB_END_DATE',
				                        margin: '0 10 10 5',
										format : 'Y/m/d',
				                        width: 100 / 1366 * screen.width,
				                        msgTarget: 'title',
				                        allowBlank: true,
				                        validateBlank: false
			                        }    
	                            ]		
		                    },
		                    {
			   		             xtype: 'fileuploadfield',
			   		             id: 'docTowContract',
			   		             emptyText: 'Select a document to upload...',
			   		             name:'FILE',
			   		             fieldLabel: 'Document',
			   		             buttonText: '...',
			   		             labelWidth: 100/1366*screen.width,
			   		             width: 315/1366*screen.width,
			   		             margin:'0 10 10 5'
		                    },
		                    {
                                xtype: 'combobox',
                                cls: 'black',
                                id : 'enabledImb',
                                name: 'ENABLED',
                                margin: '0 10 10 5',
                                labelWidth: 100 / 1366 * screen.width,
                                width: 315/1366 * screen.width,
                                fieldLabel: 'Active',
                                emptyText: 'Active',
                                store: [['True', 'Yes'], ['False', 'No']],
                                msgTarget: 'title',
                                allowBlank: true,
                                validateBlank: false
                            },
                            {
                                xtype: 'panel',
                                width: 345,
                                heigth: 100,
                                layout: 'hbox',
                                border: false,
                                margin: '0 10 0 0',
                                items: [
                                    {
                                        xtype: 'button',
                                        width: 60,
                                        height: 30,
                                        margin: '0 10 0 110',
                                        text: 'Add',
                                        id: 'btnSubmitTowImb',
                                        handler: function () {
                                            Ext.getCmp('formAssetTowImb').getForm().submit({
                                            	 waitMsg : 'Please Wait ....',
												success: function(form, action) {
													Ext.Msg.alert('Submited', action.response.responseText);
												},
												failure: function(form, action) {
													Ext.Msg.alert('Submited', action.response.responseText);
		                                            Ext.getCmp('formAssetTowImb').getForm().reset;
		                                            Ext.getStore('AssetDataMaster.AssetTowerImb').load();
												}
											});
                                        }
                                    },
                                    {
                                        xtype: 'button',
                                        width: 60,
                                        height: 30,
                                        margin: '0 10 0 45',
                                        text: 'Cancel',
                                        id: 'btnCancelTowImb',
                                        handler: function () {
                                            Ext.getCmp('formAssetTowImb').getForm().reset;
                                            Ext.getStore('AssetDataMaster.AssetTowerImb').load();
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
		            	 xtype : 'gridpanel',
		            	 id : 'gridAssetTowImb',
		            	 height : 0.33 * screen.height,
		            	 autoScroll : 'true',
		            	 width : 700,
		            	 region : 'center',
		            	 columnLines : true,
		            	 forceFit : true,
                         margin: '10 10 10 10',
		            	 store : 'AssetDataMaster.AssetTowerImb',
		            	 listeners : {
		        	 		afterrender : function() {
								
		             	 	}
		      			 },
				          columns: [
				              {dataIndex: 'IMB_NO', text: 'IMB NO', align: 'left'},
				              {dataIndex: 'IMB_START_DATE', text: 'START DATE', align: 'left'},
				              {dataIndex: 'IMB_END_DATE', text: 'END DATE', align: 'left'},
				              {
		                      	    xtype: 'actioncolumn',
		                      	    text : 'DOCUMENT',
		                      	    align : 'center',
		                      	    renderer: function (value, metadata, record) {
		                      	    	var document = record.get('ATTACH_FILE');
		                      	    	if (document=="null"){
		                      	    		this.items[0].icon = '';
		                      	    	}else{
		                      	    		var typefile=document.split(".");
		                      	    		 if (typefile[1]=="pdf"){ 
		                      	    			 this.items[0].icon = 'images/pdf-icon.png'; 
		                      	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
		                      	    			 this.items[0].icon = 'images/Word-icon.png';  
		                      	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
		                      	    			 this.items[0].icon = 'images/Excel-icon.png';  
		                      	    		 }else if (typefile[1]=="jpeg" || typefile[1]=="xls"){ 
		                      	    			 this.items[0].icon = 'images/images-icon.jpg';  
		                      	    		 }
		                      	    	}
		                      	    },
		                      	    items: [{
		                      	        tooltip: 'Show Document',
		                      	        handler: function (grid, rowIndex, colIndex) {
		                      	        	 var rec = grid.getStore().getAt(rowIndex);
		                      	        	 var typefile=rec.get('ATTACH_FILE').split(".");
		                      	        	 console.log (rec.get('ATTACH_FILE'));
		                      	        	 if (typefile[1]=="pdf"){
		                      	        		window.open('./Services/Asset/doc/pdf/'+rec.get('ATTACH_FILE')); 
		                      	        	 }else{
		                      	        		 window.open('./Services/Asset/doc/img/'+rec.get('ATTACH_FILE'));  
		                      	        	 }
		                      	        }
		                      	    }]
				              },
				              {dataIndex: 'ENABLED', text: 'ENABLED', align: 'left'}
				          ],
				            listeners : {
				                itemdblclick : function(grid, record) {
				                	var imbId = record.get('SITE_TOWER_IMB_HISTORY_ID');
				                	console.log (imbId);
			                		Ext.Ajax.request({
			                		    method: "GET",
			                		    dataType: "json",
			                		    url: "./Services/Asset/AssetTowerImb/"+imbId,
			                		    async: false	,
			                		    success: function(c) {
			                		    	var jsonResults= $.parseJSON(c.responseText);
			                		    	data = jsonResults.item[0];
			                		    	console.log (data);
			                		    	Ext.getCmp('formAssetTowImb').getForm().setValues(data);
			                		    	Ext.getCmp('btnSubmitTowImb').setText('Update');		                		        }
		                		    });	
				                }
		      			 	}	      			
		            }   
                ] 
            }
                
         ]
      }).show();

}

